package cn.edu.xmist.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * jdk动态代理
 */
public class DynamicProxy implements InvocationHandler {

    private Object object;

    public DynamicProxy(Object object) {
        this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        /**
         * 执行被代理对象方法
         */
        Object result = method.invoke(object, args);
        after();
        return result;
    }

    private void before() {
        System.out.println("我在前面");
    }

    private void after() {
        System.out.println("我在后面");
    }
}
